<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="审批分类" prop="examineId">
      <el-input v-model="dataForm.examineId" placeholder="审批分类"></el-input>
    </el-form-item>
    <el-form-item label="分类标识" prop="typeCode">
      <el-input v-model="dataForm.typeCode" placeholder="分类标识"></el-input>
    </el-form-item>
    <el-form-item label="分类主键" prop="typeId">
      <el-input v-model="dataForm.typeId" placeholder="分类主键"></el-input>
    </el-form-item>
    <el-form-item label="事项名称" prop="itemName">
      <el-input v-model="dataForm.itemName" placeholder="事项名称"></el-input>
    </el-form-item>
    <el-form-item label="申请部门ID" prop="applyDeptId">
      <el-input v-model="dataForm.applyDeptId" placeholder="申请部门ID"></el-input>
    </el-form-item>
    <el-form-item label="申请部门名称" prop="applyDeptName">
      <el-input v-model="dataForm.applyDeptName" placeholder="申请部门名称"></el-input>
    </el-form-item>
    <el-form-item label="申请人员ID" prop="applyUserId">
      <el-input v-model="dataForm.applyUserId" placeholder="申请人员ID"></el-input>
    </el-form-item>
    <el-form-item label="申请人员名称" prop="applyUserName">
      <el-input v-model="dataForm.applyUserName" placeholder="申请人员名称"></el-input>
    </el-form-item>
    <el-form-item label="审批状态（审批中、退回中、已结束、已撤销）" prop="examineZt">
      <el-input v-model="dataForm.examineZt" placeholder="审批状态（审批中、退回中、已结束、已撤销）"></el-input>
    </el-form-item>
    <el-form-item label="当前环节ID" prop="detailsId">
      <el-input v-model="dataForm.detailsId" placeholder="当前环节ID"></el-input>
    </el-form-item>
    <el-form-item label="当前环节名称" prop="detailsMc">
      <el-input v-model="dataForm.detailsMc" placeholder="当前环节名称"></el-input>
    </el-form-item>
    <el-form-item label="当前部门ID" prop="currentDeptId">
      <el-input v-model="dataForm.currentDeptId" placeholder="当前部门ID"></el-input>
    </el-form-item>
    <el-form-item label="当前部门名称" prop="currentDeptName">
      <el-input v-model="dataForm.currentDeptName" placeholder="当前部门名称"></el-input>
    </el-form-item>
    <el-form-item label="当前人员ID" prop="currentUserId">
      <el-input v-model="dataForm.currentUserId" placeholder="当前人员ID"></el-input>
    </el-form-item>
    <el-form-item label="当前人员名称" prop="currentUserName">
      <el-input v-model="dataForm.currentUserName" placeholder="当前人员名称"></el-input>
    </el-form-item>
    <el-form-item label="开始时间" prop="startTime">
      <el-input v-model="dataForm.startTime" placeholder="开始时间"></el-input>
    </el-form-item>
    <el-form-item label="结束时间" prop="endTime">
      <el-input v-model="dataForm.endTime" placeholder="结束时间"></el-input>
    </el-form-item>
    <el-form-item label="建立时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="建立时间"></el-input>
    </el-form-item>
    <el-form-item label="修改时间" prop="editTime">
      <el-input v-model="dataForm.editTime" placeholder="修改时间"></el-input>
    </el-form-item>
    <el-form-item label="建立部门ID" prop="createDeptId">
      <el-input v-model="dataForm.createDeptId" placeholder="建立部门ID"></el-input>
    </el-form-item>
    <el-form-item label="建立部门" prop="createDeptName">
      <el-input v-model="dataForm.createDeptName" placeholder="建立部门"></el-input>
    </el-form-item>
    <el-form-item label="建立人员ID" prop="createUserId">
      <el-input v-model="dataForm.createUserId" placeholder="建立人员ID"></el-input>
    </el-form-item>
    <el-form-item label="建立人员" prop="createUserName">
      <el-input v-model="dataForm.createUserName" placeholder="建立人员"></el-input>
    </el-form-item>
    <el-form-item label="修改部门ID" prop="editDeptId">
      <el-input v-model="dataForm.editDeptId" placeholder="修改部门ID"></el-input>
    </el-form-item>
    <el-form-item label="修改部门" prop="editDeptName">
      <el-input v-model="dataForm.editDeptName" placeholder="修改部门"></el-input>
    </el-form-item>
    <el-form-item label="修改人员ID" prop="editUserId">
      <el-input v-model="dataForm.editUserId" placeholder="修改人员ID"></el-input>
    </el-form-item>
    <el-form-item label="修改人员" prop="editUserName">
      <el-input v-model="dataForm.editUserName" placeholder="修改人员"></el-input>
    </el-form-item>
    <el-form-item label="数据状态（0删除、1正常）" prop="dataState">
      <el-input v-model="dataForm.dataState" placeholder="数据状态（0删除、1正常）"></el-input>
    </el-form-item>
    <el-form-item label="所属租户" prop="tenantId">
      <el-input v-model="dataForm.tenantId" placeholder="所属租户"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      
      <el-button type="primary" @click="dataFormSubmit()" v-if="canSubmit">确定</el-button>
      <el-button @click="visible = false">取消</el-button>
    </span>
  </el-dialog>
</template>

<script>
    import {getObj, addObj, putObj} from '@/api/admin/sysexaminemain'

    export default {
    data () {
      return {
        visible: false,
        canSubmit: false,
        dataForm: {
          mainId: 0,
          examineId: '',
          typeCode: '',
          typeId: '',
          itemName: '',
          applyDeptId: '',
          applyDeptName: '',
          applyUserId: '',
          applyUserName: '',
          examineZt: '',
          detailsId: '',
          detailsMc: '',
          currentDeptId: '',
          currentDeptName: '',
          currentUserId: '',
          currentUserName: '',
          startTime: '',
          endTime: '',
          createTime: '',
          editTime: '',
          createDeptId: '',
          createDeptName: '',
          createUserId: '',
          createUserName: '',
          editDeptId: '',
          editDeptName: '',
          editUserId: '',
          editUserName: '',
          dataState: '',
          tenantId: ''
        },
        dataRule: {
          examineId: [
            { required: true, message: '审批分类不能为空', trigger: 'blur' }
          ],
          typeCode: [
            { required: true, message: '分类标识不能为空', trigger: 'blur' }
          ],
          typeId: [
            { required: true, message: '分类主键不能为空', trigger: 'blur' }
          ],
          itemName: [
            { required: true, message: '事项名称不能为空', trigger: 'blur' }
          ],
          applyDeptId: [
            { required: true, message: '申请部门ID不能为空', trigger: 'blur' }
          ],
          applyDeptName: [
            { required: true, message: '申请部门名称不能为空', trigger: 'blur' }
          ],
          applyUserId: [
            { required: true, message: '申请人员ID不能为空', trigger: 'blur' }
          ],
          applyUserName: [
            { required: true, message: '申请人员名称不能为空', trigger: 'blur' }
          ],
          examineZt: [
            { required: true, message: '审批状态（审批中、退回中、已结束、已撤销）不能为空', trigger: 'blur' }
          ],
          detailsId: [
            { required: true, message: '当前环节ID不能为空', trigger: 'blur' }
          ],
          detailsMc: [
            { required: true, message: '当前环节名称不能为空', trigger: 'blur' }
          ],
          currentDeptId: [
            { required: true, message: '当前部门ID不能为空', trigger: 'blur' }
          ],
          currentDeptName: [
            { required: true, message: '当前部门名称不能为空', trigger: 'blur' }
          ],
          currentUserId: [
            { required: true, message: '当前人员ID不能为空', trigger: 'blur' }
          ],
          currentUserName: [
            { required: true, message: '当前人员名称不能为空', trigger: 'blur' }
          ],
          startTime: [
            { required: true, message: '开始时间不能为空', trigger: 'blur' }
          ],
          endTime: [
            { required: true, message: '结束时间不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '建立时间不能为空', trigger: 'blur' }
          ],
          editTime: [
            { required: true, message: '修改时间不能为空', trigger: 'blur' }
          ],
          createDeptId: [
            { required: true, message: '建立部门ID不能为空', trigger: 'blur' }
          ],
          createDeptName: [
            { required: true, message: '建立部门不能为空', trigger: 'blur' }
          ],
          createUserId: [
            { required: true, message: '建立人员ID不能为空', trigger: 'blur' }
          ],
          createUserName: [
            { required: true, message: '建立人员不能为空', trigger: 'blur' }
          ],
          editDeptId: [
            { required: true, message: '修改部门ID不能为空', trigger: 'blur' }
          ],
          editDeptName: [
            { required: true, message: '修改部门不能为空', trigger: 'blur' }
          ],
          editUserId: [
            { required: true, message: '修改人员ID不能为空', trigger: 'blur' }
          ],
          editUserName: [
            { required: true, message: '修改人员不能为空', trigger: 'blur' }
          ],
          dataState: [
            { required: true, message: '数据状态（0删除、1正常）不能为空', trigger: 'blur' }
          ],
          tenantId: [
            { required: true, message: '所属租户不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.mainId = id || 0;
        this.visible = true;
        this.canSubmit = true;
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.mainId) {
            getObj(this.dataForm.mainId).then(response => {
                this.dataForm = response.data.data
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.canSubmit = false;
            if (this.dataForm.mainId) {
                putObj(this.dataForm).then(data => {
                    this.$notify.success('修改成功')
                    this.visible = false
                    this.$emit('refreshDataList')
                }).catch(() => {
                    this.canSubmit = true;
                });
            } else {
                addObj(this.dataForm).then(data => {
                    this.$notify.success('添加成功')
                    this.visible = false
                    this.$emit('refreshDataList')
                }).catch(() => {
                    this.canSubmit = true;
                });
            }
          }
        })
      }
    }
  }
</script>
